package task1;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-05-26
 * Time:16:59
 */
public class TestDemo {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack=new Stack<Integer>();
        int j=0;
        for (int i = 0; i < pushed.length; i++) {
            stack.push(pushed[i]);
            while(!stack.empty()&&popped[j]==stack.peek()){
                j++;
                stack.pop();
            }
        }
        return stack.empty();
    }
}
